//
//  JSBookReaderManager.h
//  NiubilityProject
//
//  Created by Apple on 2018/5/24.
//  Copyright © 2018年 Apple. All rights reserved.
//

#import <Foundation/Foundation.h>

@class JSReaderBook,JSReaderChapter,JSReaderModel,JSReaderPager,JSRenderConfig;


/*! 获取到当前页data block */
typedef void( ^ JSReaderPageData)(JSReaderPager *data);

@protocol JSBookPageStyleDelegate <NSObject>

/** 重置翻页样式 */
-(void)resetingBookPageStyle:(NSInteger)style;


@end
@protocol JSBookContenDateSource <NSObject>


/** 渲染内容区域大小 */
-(CGSize)renderSize;

@optional
/** 设置字体大小 */
-(NSInteger)resetingFoneSize;

@end
@protocol JSBookContenDateDelegate <NSObject>

@optional
/** 获取到整本书的信息 */
-(void)reciveBookData:(JSReaderBook *)data;
/** 获取到章节信息 */
-(void)reciveChapterData:(JSReaderChapter *)data isRenader:(BOOL)renader;

/*!
 获取到指定页信息
 
 reander 是否需要渲染界面
 */
-(void)recivePageData:(JSReaderPager *)data isRenader:(BOOL)renader;
/*!
 开始请求数据
 
 通知外界正在请求数据 让外界做相关操作
 */
-(void)startRequestData;


@end


@interface JSBookReaderManager : NSObject

+ (JSBookReaderManager *)sharedJSBookReaderManager;
@property (nonatomic, strong) JSRenderConfig *renderConfig;
#warning 代理方法中 isReader 是根据 block是否有值决定的
@property (nonatomic, copy) JSReaderPageData pageDataBlock; // 用于获取和当前章节不同的下一页数据
@property (nonatomic, strong, readonly) JSReaderBook *curBook;

@property (nonatomic, strong, readonly) JSReaderChapter *prepareUpChapter;
@property (nonatomic, strong, readonly) JSReaderChapter *curChapter;
@property (nonatomic, strong, readonly) JSReaderChapter *prepareNextChapter;

@property (nonatomic, strong, readonly) JSReaderModel *curReaderModel; // 界面渲染属性

@property (nonatomic, weak) id<JSBookPageStyleDelegate> pageDelegate;
@property (nonatomic, weak) id<JSBookContenDateSource> contentDataSource;
@property (nonatomic, weak) id<JSBookContenDateDelegate> contentDataDelegate;

@property (nonatomic, assign, readonly) CGSize curRenderSize;

@property (nonatomic, assign, readonly) NSInteger duringReaderPagelIndex; // 正在渲染
@property (nonatomic, assign, readonly) NSInteger duringReaderChapterIndex;

@property (nonatomic, strong, readonly) NSMutableArray *BePrecached;



// 根据id获取整本书信息
-(void)loadBookData:(NSInteger)bookId;
// 根据index获取章节信息
-(void)loadChapterData:(NSInteger)index;
// 根据url获取章节信息 待实现
//-(void)loadOnLineChapterData:(NSURL *)url;
// 根据章节信息和浏览标记获取指定页信息
//-(void)reanderPageData:(JSReaderChapter *)chapter mark:(NSInteger )pageIdex;
// 获取指定章节指定页内容
//-(void)loadChapterIndex:(NSInteger)chapterIndex pageIndex:(NSInteger)pageIndex pageData:(JSReaderPageData)data;

#warning 此block回调完成后 需要将 pageDataBlock = nil;
//获取上一页数据
-(JSReaderPager *)loadUpPageData:(JSReaderPageData)data;
//获取下一页数据
-(JSReaderPager *)loadNextPageData:(JSReaderPageData)data;

//字体大小
- (void)increaseChangeSizeAction;
- (void)decreaseChangeSizeAction;

-(BOOL)havePreChapter;
-(BOOL)haveNextChapter;
// 切换完成
-(void)changeFinish;



// 通知
-(void)registerRunLoopObserver;
-(void)cancelRunloopObserver;
/*
 第一次加载 根据 书本id 浏览记录 获取一页数据
 */
-(void)loadFromBook:(NSInteger)bookId PageData:(JSReaderPageData)data;

/*!
 获取指定页数据
 

 */
-(void)skillToBook:(NSInteger )bookId chapter:(NSInteger )chapterIndex page:(NSInteger)pageIndex pageData:(JSReaderPageData)data;


@end
